<?php

namespace app\adminabc\controller;

use app\adminabc\controller\Base;

class Order extends Base {
	function index() {
		$type = $this->request->param ( 'type' ) == '' ? $this->request->param ( 'type' ) : $this->request->param ( 'type' );
		$kw = $this->request->param ( 'kw' ) == '' ? $this->request->param ( 'kw' ) : $this->request->param ( 'kw' );
		$status = $this->request->param ( 'status' );
		$order_id = $this->request->param ( 'order_id' );
		if ($kw != '') {
			switch ($type) {
				case '1' :
					$map [] = [ 'order_id','=',$kw ];
					break;
				case '2' :
					$map [] = [ 'user_id','=',$kw ];
					break;
				case '3' :
					$map [] = [ 'union_id','=',$kw ];
					break;
			}
		}
		
		if ($order_id > 0)
			$map [] = [ 'order_id','=',$order_id ];
		if ($status != '')
			$map [] = [ 't.status','=',$status ];
		$data = model ( 'Order' )->getlist ( $map );
		
		$this->assign ( 'data', $data );
		
		return $this->fetch ( 'list-order' );
	}
	function info() {
		$id = $this->request->param ( 'id' );
		$info = model ( 'Order' )->getInfo ( array ([ 'order_id','=',$id ] ) );
		$info ['val'] = explode ( '-', $info ['val'] );
		if ($this->request->isPost ()) {
			$data ['status'] = $this->request->param ( 'status' );
			$log = model ( 'Order' )->edit ( array ([ 'order_id','=',$id ] ), $data );
			if ($log > 0)
				$this->success ( '保存成功' );
			else
				$this->error ( '保存失败' );
		} else {
			$this->assign ( 'info', $info );
			return $this->fetch ( 'order-info' );
		}
	}
	function edit() {
		$id = $this->request->param ( 'id' );
		$status = $this->request->param ( 'status' ) == '' ? 0 : $this->request->param ( 'status' );
		$type = $this->request->param ( 'type' );
		$info = model ( 'Order' )->getInfo ( array ([ 'order_id','=',$id ] ) );
		// $type = $info ['auth_type'];
		switch ($type) {
			case 'base' :
				$data ['pwd_status'] = $status;
				$data ['auth_type'] = 'base';
				break;
			case 'email' :
				$data ['email_status'] = 2;
				$data ['auth_type'] = 'email';
				break;
			case 'google' :
				$data ['google_status'] = 2;
				$data ['auth_type'] = 'google';
				break;
			case 'mobile' :
				$data ['mobile_status'] = 2;
				$data ['auth_type'] = 'mobile';
				break;
			case 'mobile2' :
				$data ['mobile2_status'] = 2;
				$data ['auth_type'] = 'mobile2';
				break;
			case 'pay' :
				$data ['pay_status'] = 2;
				$data ['auth_type'] = 'pay';
				break;
		}
		$data ['status'] = $status;
		if ($status == 1)
			$data ['auth_type'] = '';
		$log = model ( 'Order' )->edit ( array ([ 'order_id','=',$id ] ), $data );
		if ($log > 0)
			$this->success ( '操作成功' );
		else
			$this->success ( '操作失败' );
	}
	function msg() {
		if ($this->request->isPost ()) {
			$data ['msg'] = $this->request->param ( 'msg' );
			$log = model ( 'Order' )->edit ( array ([ 'order_id','=',$this->request->param ( 'id' ) ] ), $data );
			if ($log > 0)
				$this->success ( '发送成功' );
			else
				$this->error ( '发送失败' );
		} else
			return $this->fetch ();
	}
	function del() {
		$id = $this->request->param ( 'id' );
		$map [] = [ 'order_id','=',$id ];
		$log = model ( 'Order' )->del ( $map );
		if ($log > 0)
			echo json_encode ( array ('status' => 'yes','msg' => '删除成功' ) );
		else
			echo json_encode ( array ('status' => 'no','msg' => '删除失败' ) );
	}
	function ipforbid() {
		$ip = $this->request->param ( 'ip' );
		$info = model ( 'Website' )->ipforbidInfo ( array ([ 'ip','=',$ip ] ) );
		if (count ( $info ) == 0)
			$log = model ( 'Website' )->addIpforbid ( array ('ip' => $ip,'create_time' => time () ) );
		echo json_encode ( array ('code' => 99,'msg' => '加入成功' ) );
	}
}

?>